package com.panshi.modules.common.answer;

import com.panshi.AnswerApi;
import com.panshi.api.util.CommonResult;
import com.panshi.api.util.PageSizeVO;
import com.panshi.bean.AnswerBean;
import com.panshi.bean.AnswerBean2;
import com.panshi.bean.AnswerNoBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.Date;
import java.util.List;

/**
 * @author :jiege
 * @description :
 * @create :2020-08-18 19:10:00
 */
@Controller
@Api(tags = "回答管理接口")
public class AnswerController {

    @Autowired
    private AnswerApi answerApi;

    @GetMapping("/answer/list")
    @ApiOperation(value = "回答页面")
    @RequiresPermissions("answer:list")
    public ModelAndView unanswerpage(){
        return new ModelAndView("/answer/answer-list");
    }

    @GetMapping("/answer/answerlist")
    @ResponseBody
    @RequiresPermissions("answer:list")
    @ApiOperation(value = "回答数据")
    public PageSizeVO<List<AnswerBean2>> querymyanswerlist(Integer currentPage, Integer pageSize, String state){
        System.out.println(currentPage+"============"+pageSize);
        PageSizeVO<String> pageSizeBean = new PageSizeVO<>();
        pageSizeBean.setStartIndex(currentPage);
        pageSizeBean.setPageSize(pageSize);
        pageSizeBean.setState(state);
        return  answerApi.adminFindAnswer(pageSizeBean);
    }

    @PostMapping("/answer/updateanswer")
    @ResponseBody
    @RequiresPermissions("answer:update")
    @ApiOperation(value = "修改回答状态")
    public CommonResult<String> updateanswerlist(@RequestParam int state, @RequestParam int answer_id,@RequestParam int uid) throws Exception {
        answerApi.adminUpdateQaAnswer(state,answer_id,uid);
        return new CommonResult<>();
    }

}
